import 'package:flutter/material.dart';
import 'package:gevbi/providers/hide_play_button_provider.dart';
import 'package:gevbi/providers/theme_provider.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'dart:io';

class SettingsScreen extends StatefulWidget {
  @override
  _SettingsScreenState createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
  String? appName;
  String? packageName;
  String? version;
  String? buildNumber;

  @override
  void initState() {
    super.initState();
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      setState(() {
        appName = packageInfo.appName;
        packageName = packageInfo.packageName;
        version = packageInfo.version;
        buildNumber = packageInfo.buildNumber;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    final checkTheme = Provider.of<ThemeProvider>(context);
    final checkButtonState = Provider.of<HidePlayButtonProvider>(context);
    return Material(
      child: Container(
        width: MediaQuery.of(context).size.width,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: [
              checkTheme.mTheme == false
                  ? Color.fromARGB(255, 149, 93, 214)
                  : Color.fromARGB(255, 0, 136, 255),
              checkTheme.mTheme == false
                  ? Color.fromARGB(255, 57, 128, 187)
                  : Color.fromARGB(255, 0, 251, 255),
              checkTheme.mTheme == false
                  ? Color.fromARGB(255, 66, 146, 211)
                  : Color.fromARGB(255, 2, 226, 230),
              checkTheme.mTheme == false
                  ? Color.fromARGB(255, 77, 217, 242)
                  : Color.fromARGB(255, 60, 210, 187),
              checkTheme.mTheme == false
                  ? Color.fromARGB(255, 120, 247, 213)
                  : Color.fromARGB(255, 84, 196, 166),
            ],
            end: Alignment.topLeft,
            begin: Alignment.bottomCenter,
          ),
        ),
        child: Container(
          padding: EdgeInsets.fromLTRB(20, 50, 150, 20),
          child: Column(
            children: [
              Container(
                width: 300,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '随心小记',
                      style: TextStyle(fontSize: 30),
                    ),
                  ],
                ),
              ),
              SizedBox(height: 10),
              ListTile(
                leading: Icon(
                  checkTheme.mTheme == false
                      ? Icons.brightness_3
                      : Icons.brightness_6,
                  size: 30,
                ),
                title: Text(
                  '夜间模式',
                  style: TextStyle(fontSize: 15),
                ),
                subtitle: Text(
                  '切换日间夜间模式',
                  style: TextStyle(fontSize: 10),
                ),
                trailing: Switch(
                  value: checkTheme.mTheme,
                  onChanged: (val) {
                    checkTheme.checkTheme();
                  },
                ),
              ),
              SizedBox(height: 10),
              ListTile(
                leading: Icon(
                  Icons.play_arrow,
                  size: 30,
                ),
                title: Text(
                  '文字转音频',
                  style: TextStyle(fontSize: 15),
                ),
                subtitle: Text(
                  checkButtonState.mPlayButton ? '功能已关闭' : '功能已开启',
                  style: TextStyle(fontSize: 10),
                ),
                trailing: Switch(
                  value: !checkButtonState.mPlayButton,
                  onChanged: (val) {
                    checkButtonState.checkButtonState();
                  },
                ),
              ),
              SizedBox(height: 10),
              Text(
                '随心小记是一款可以让您随时随地记录所思所想的便捷备忘app，并在您需要的时候，迅速地将文字转换为音频播放。是您手机里的可靠助手！',
                style: TextStyle(
                  fontSize: 12,
                  height: 2,
                  letterSpacing: 1,
                ),
                textAlign: TextAlign.left,
              )
            ],
          ),
        ),
      ),
    );
  }
}
